const router = require('koa-router')()

//引入db里面自己写的连接数据库端口
const {query} = require('../db/index')

//全部数据
router.get('/api/list', async (ctx, next) => {
  //语句
  const sql=` select * from shop `
  const data=await query(sql)
  ctx.body=data
})

//id数据  // 详情
router.get('/api/find', async (ctx, next) => {
  const {id}=ctx.query
  const sql=` select * from shop where id=${id}`
 
  const data=await query(sql)
  ctx.body=data
})

//查找


//删除
router.delete('/api/del',async(ctx,next)=>{
  //根据id删除
  const {id}=ctx.query
  const sql=` delete from shop where id=${id} `
  //虽然没用到data 但是还是要写不然没效果，不知道为啥
  const data=query(sql)

  //返回删除后最新的数据
  const sql1=` select * from shop `
  const data1=await query(sql1)
  // console.log(data)

  ctx.body=data1


})


//登录注册

router.post('/api/')




router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})

// 

module.exports = router
